package com.exam.springbootexam.service.impl;
import com.exam.springbootexam.entity.Class;
import com.exam.springbootexam.entity.PageEntity;
import com.exam.springbootexam.entity.Student;
import com.exam.springbootexam.mapper.ClassMapper;
import com.exam.springbootexam.service.ClassService;
//import jakarta.annotation.Resource;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 十五
 */
@Service
public class ClassServiceImpl implements ClassService {
    @Resource
    private ClassMapper classMapper;

    /**
     * 分页查询班级
     *
     * @param current  Integer 当前页数
     * @param pageSize Integer 每页显示数量
     * @return PageEntity<Class>
     */
    @Override
    public PageEntity<Class> selectByPage(Integer current, Integer pageSize) {
        //查询总数
        int total = classMapper.selectCont();
        //分页查询数据
        List<Class> users = classMapper.selectLimit((current - 1) * pageSize, pageSize);
        PageEntity<Class> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(users);
        return pageEntity;
    }

    /**
     * 查询所有班级
     *
     * @return List<Class>
     */
    @Override
    public List<Class> selectAll() {
        return classMapper.selectAll();
    }

    /**
     * 按classId查询班级
     *
     * @param clazzId String
     * @return Class
     */
    @Override
    public Class selectById(Integer clazzId) {
        return classMapper.selectById(clazzId);
    }

    /**
     * 模糊查询
     *
     * @param keyword String
     * @return
     */
    @Override
    public List<Class> serachByKeyword(String keyword) {
        return classMapper.search(keyword);
    }

    /**
     * 添加班级
     *
     * @param clazz Class
     * @return boolean
     */
    @Override
    public boolean add(Class clazz) {
        return classMapper.add(clazz);
    }

    /**
     * 删除班级
     *
     * @param classId String
     * @return boolean
     */
    @Override
    public boolean delete(Integer classId) {
        return classMapper.delete(classId);
    }

    /**
     * 更新班级
     *
     * @param clazz Class
     * @return boolean
     */
    @Override
    public boolean update(Class clazz) {
        return classMapper.update(clazz);
    }
}
